# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=ghex
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=46.2
pkgrel=1
pkgdesc="A simple binary editor for the Gnome desktop (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://wiki.gnome.org/Apps/Ghex"
msys2_repository_url="https://gitlab.gnome.org/GNOME/ghex"
license=("spdx:GPL-2.0-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-libadwaita"
         "${MINGW_PACKAGE_PREFIX}-gtk4"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-desktop-file-utils")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-nohelp.patch
        002-fread.patch
        003-gui-app.patch)
sha256sums=('a8f276a36397a70d20b862ff7c664243d9cf2891deb9be06d745a4f1ac661f31'
            '30a351ef0c0b0bc319edec222de5222879b8eecfb58237e5b25c3c1dccf02788'
            'bd356348c1e017003e97f390f06297f99120f3640ab11874d5b37045a38726bb'
            '571b4c8189cfb371f2aba0621cc68877a8e188896eef2cd7217ff1eed78e7eb2')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}"/001-nohelp.patch
  patch -Np1 -i "${srcdir}"/002-fread.patch
  patch -Np1 -i "${srcdir}"/003-gui-app.patch
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Ddefault_library=both \
    -Dmmap-buffer-backend=false \
    -Ddirect-buffer-backend=false \
    -Dintrospection=enabled \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}" --destdir "${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
